package com.alstudio.app;

import android.app.Application;
import android.content.Context;
import android.content.Intent;

import com.alstudio.net.EventHandler.UIEventHandler;
import com.alstudio.net.protocol.xmpp.XmppAdapter;
import com.alstudio.net.protocol.xmpp.XmppEventNotifyManager;
import com.alstudio.service.BackgroundService;
import com.alstudio.utils.ALActivityManager;
import com.alstudio.utils.notification.NoticeItemManager;
import com.alstudio.utils.notification.NoticeItemShowController;

public class LocalEnv extends Application {

	/* 此变量用于UI传递xmpp操作到底层 */
	public static UIEventHandler mUIEventHandler;
	public static XmppAdapter adapter;

	/* 此变量用于创建xmpp事件管理器，通过此管理器，驱动UI更新界面 */
	public static XmppEventNotifyManager mXmppEventNotifyManager;
	/* 版本信息 */
	public static final String VERSION = "V1.0.0";
	public static final String BUILD_CODE = "1001";

	public static Context mContext = null;

	public static NoticeItemManager mNoticeItemManager;
	private NoticeItemShowController mNoticeItemShowController;

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		// 初始化本地环境变量
		initLocalEnv();
		// 启动service
		startLocalService();
	}

	/**
	 * 初始化本地全局变量
	 * 
	 * @author Alonso Lee
	 */
	private void initLocalEnv() {
		// 上下文
		mContext = this;
		// 创建UI事件监听器
		mUIEventHandler = new UIEventHandler();
		// 创建xmpp事件管理器
		mXmppEventNotifyManager = new XmppEventNotifyManager();
		mNoticeItemManager = new NoticeItemManager();

		mNoticeItemShowController = new NoticeItemShowController();

		LocalEnv.mNoticeItemManager
				.setNoticeItemManager(mNoticeItemShowController);
		ALActivityManager.getALActivityManager().setActivityLifeCycleListener(
				mNoticeItemShowController);
	}

	/**
	 * 启动后台服务
	 * 
	 * @author Alonso Lee
	 */
	private void startLocalService() {
		Intent i = new Intent(this, BackgroundService.class);
		startService(i);
	}

}
